package club.justwill.single.assembler;

import club.justwill.single.bean.Stick.CommentResp;
import club.justwill.single.bean.Stick.StickResp;
import club.justwill.single.persistence.document.Comments;
import club.justwill.single.persistence.document.Stick;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by xiangnan on 16-1-18.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class StickAssemble {
    public CommentResp assembleComment(Comments comments) {
        return new CommentResp(comments);
    }

    public List<CommentResp> assembleCommentList(List<Comments> commentsList) {
        List<CommentResp> commentRespList = new LinkedList<CommentResp>();
        for(Comments comments : commentsList) {
            commentRespList.add(assembleComment(comments));
        }
        return commentRespList;
    }

    public StickResp assembleStick(Stick stick) {
        StickResp stickResp = new StickResp();
        stickResp.setStickId(stick.getId());
        stickResp.setCommentRespList(assembleCommentList(stick.getProjectComments()));
        return stickResp;
    }

    public List<StickResp> assembleStickList(List<Stick> stickList) {
        List<StickResp> stickRespList = new LinkedList<StickResp>();
        for(Stick stick : stickList) {
            stickRespList.add(assembleStick(stick));
        }
        return stickRespList;
    }
}
